package com.example.zheng.qq.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.zheng.qq.R;
import com.example.zheng.qq.entity.Information;

import java.util.List;


public class Card extends RecyclerView.Adapter<Card.ViewHolder> {
    private List<Information> list;
    private Context context;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        if(context==null){
            context=parent.getContext();
        }
        View view= LayoutInflater.from(context).inflate(R.layout.card,parent,false);
        return new ViewHolder(view);
    }

    public Card(List<Information> list){
        this.list=list;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
         Information information=list.get(position);
        holder.textView.setText(information.getDescription());
        Glide.with(context).load(information.getPictureId()).into(holder.imageView);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        CardView cardView;
        ImageView imageView;
        TextView textView;
        public ViewHolder(View itemView) {
            super(itemView);
            cardView=(CardView)itemView;
            imageView=(ImageView)cardView.findViewById(R.id.card);
            textView=(TextView)cardView.findViewById(R.id.cardInfo);
        }
    }

}
